//
//  AddGroupHeaderView.m
//  Findif
//
//  Created by Mac on 2019/2/20.
//  Copyright © 2019年 Cicel Chen. All rights reserved.
//

#import "AddGroupHeaderView.h"

@interface AddGroupHeaderView ()

@property (nonatomic, strong)UIButton * eatButton;
@property (nonatomic, strong)UIButton * playButton;
@property (nonatomic, strong)UIButton * sportButton;
@property (nonatomic, strong)UIButton * travelButton;
@property (nonatomic, weak)UIImageView * groupImageView;
@property (nonatomic, weak)UILabel * groupLabel;

@end

@implementation AddGroupHeaderView

- (instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithReuseIdentifier:reuseIdentifier]) {
        
        [self setupUI];
    }
    return self;
}


- (void)setupUI{
 
    self.eatButton = [self setupButtonWith:@"吃喝-分类"];
    [self addSubview:self.eatButton];
    self.playButton = [self setupButtonWith:@"玩乐-分类"];
    [self addSubview:self.playButton];
    self.sportButton = [self setupButtonWith:@"运动-分类"];
    [self addSubview:self.sportButton];
    self.travelButton = [self setupButtonWith:@"旅行-分类"];
    [self addSubview:self.travelButton];
    
    UIImageView * groupImageView = [UIImageView new];
    
    groupImageView.image = [UIImage imageNamed:@"社团推荐"];
    
    self.groupImageView = groupImageView;
    
    [self addSubview:self.groupImageView];
    
    UILabel * groupLabel = [UILabel new];
    
    groupLabel.text = @"社团推荐";
    groupLabel.textColor = ZRBlackColor;
    groupLabel.font = [UIFont systemFontOfSize:14 * SCREENH6];
    
    self.groupLabel = groupLabel;
    
    [self addSubview:self.groupLabel];
}


-(void)layoutSubviews{
    
    [self.eatButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self).offset(45 * SCREENH6);
        make.top.mas_equalTo(self).offset(10 * SCREENH6);
        make.width.mas_equalTo(40 * SCREENH6);
        make.height.mas_equalTo(57 * SCREENH6);
    }];
    
    [self.playButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.eatButton.mas_trailing).offset(40 * SCREENH6);
        make.centerY.width.height.mas_equalTo(self.eatButton);
    }];
    
    [self.sportButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.playButton.mas_trailing).offset(40 * SCREENH6);
        make.centerY.width.height.mas_equalTo(self.playButton);
    }];
    
    [self.travelButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.sportButton.mas_trailing).offset(40 * SCREENH6);
        make.centerY.width.height.mas_equalTo(self.sportButton);
    }];
    
    [self.groupImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self).offset(15 * SCREENH6);
        make.top.mas_equalTo(self.eatButton.mas_bottom).offset(15 * SCREENH6);
        make.height.width.mas_equalTo(21 * SCREENH6);
    }];
    
    [self.groupLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.groupImageView.mas_trailing).offset(5 * SCREENH6);
        make.centerY.mas_equalTo(self.groupImageView);
    }];
}


- (UIButton *)setupButtonWith:(NSString *)img{
    
    UIButton * button = [UIButton new];
    NSString * selectImg = [NSString stringWithFormat:@"%@选中",img];
    [button setImage:[UIImage imageNamed:img] forState:UIControlStateNormal];
    [button setImage:[UIImage imageNamed:selectImg] forState:UIControlStateSelected];
    [button addTarget:self action:@selector(clickButton:) forControlEvents:UIControlEventTouchUpInside];
    
    
    return button;
}


- (void)clickButton:(UIButton *)button{
    
    NSString * code;
    if (button == self.eatButton) {
        
        code = @"1137";
    }else if (button == self.playButton){
        
        code = @"1138";
    }else if (button == self.sportButton){
        
        code = @"1139";
    }else if (button == self.travelButton){
        
        code = @"1140";
    }
    
    if (self.delegate && [self.delegate respondsToSelector:@selector(clickCategoryButtonWithType:)])
    {
        
        [self.delegate clickCategoryButtonWithType:code];
    }
}

@end
